//响应拦截器
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,
  CallHandler,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class ResponseInterceptor implements NestInterceptor {
  intercept(
    context: ExecutionContext,
    next: CallHandler<any>,
  ): Observable<any> | Promise<Observable<any>> {
    const status = context.switchToRpc().getData().res.statusCode;
    return next.handle().pipe(
      map((data) => {
        return {
          code: status,
          message: 'success',
          data,
        };
      }),
    );
  }
}
